﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using erpIngesup.Functions;
using erpIngesup.Areas.Eleve.Models;

namespace erpIngesup.Areas.Eleve.Controllers
{
    public class EventController : Controller
    {
        private bddIngesupEntitiesEleve db = new bddIngesupEntitiesEleve();
        //
        // GET: /Eleve/Event/

        public ActionResult Index(string langue)
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Field.getLanguage(langue));
            string login = Session["login"] != null ? Session["login"].ToString() : "stevix";
            string year = DateTime.Now.Year.ToString();
            /*var examNext = db.PROJET.SingleOrDefault(x => x.DATE_DBT_PROJ >= DateTime.Now && x.MODULE.CLASSE.ELEVE.SingleOrDefault().LOGINPERS == login);
            var examPrev = db.PROJET.SingleOrDefault(x => x.DATE_DBT_PROJ <= DateTime.Now && x.MODULE.CLASSE.ELEVE.SingleOrDefault().LOGINPERS == login);
            var eventPrev = db.COURS.Where(x => x.DATE_DBT <= DateTime.Now && x.MODULE.CLASSE.IDCLASSE == db.ELEVECLASSE.SingleOrDefault(y => y.ANNEECLASSE == year && y.ELEVE.LOGINPERS == login).IDCLASSE);
            var eventNext = db.COURS.Where(x => x.DATE_DBT >= DateTime.Now && x.MODULE.CLASSE.IDCLASSE == db.ELEVECLASSE.SingleOrDefault(y => y.ANNEECLASSE == year && y.ELEVE.LOGINPERS == login).IDCLASSE).Union(eventPrev);
            */
            int idClasse = db.ELEVE.SingleOrDefault(x => x.LOGINPERS == login).CLASSE.IDCLASSE;
            CLASSE c = db.CLASSE.SingleOrDefault(x => x.IDCLASSE == idClasse);
            return View(c);
        }

        public PartialViewResult coursPrev(string langue, CLASSE c)
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Field.getLanguage(langue));
            string login = Session["login"] != null ? Session["login"].ToString() : "";
            string year = DateTime.Now.Year.ToString();
            var coursPrev = db.COURS.Where(x => x.DATE_FIN <= DateTime.Now && x.MODULE.CLASSE.IDCLASSE == c.IDCLASSE).Take(2).OrderBy(x => x.DATE_FIN).ToList();
            return PartialView(coursPrev);
        }

        public PartialViewResult coursNext(string langue, CLASSE c)
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Field.getLanguage(langue));
            string login = Session["login"] != null ? Session["login"].ToString() : "";
            string year = DateTime.Now.Year.ToString();
            var coursNext = db.COURS.Where(x => x.DATE_DBT >= DateTime.Now && x.MODULE.CLASSE.IDCLASSE == c.IDCLASSE).Take(2).OrderBy(x => x.DATE_DBT).ToList();
            return PartialView(coursNext);
        }

        public PartialViewResult Exams(string langue, CLASSE c)
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Field.getLanguage(langue));
            string year = DateTime.Now.Year.ToString();
            var exams = db.EVALUATION.Where(x => x.DATE_EVAL >= DateTime.Now && x.MODULE.CLASSE.IDCLASSE == c.IDCLASSE).Take(2).OrderBy(x => x.DATE_EVAL).ToList();
            return PartialView(exams);
        }

    }
}
